package com.ksyun.alert.converter;

import com.ksyun.alert.utils.TimestampConverter;
import org.apache.commons.beanutils.converters.DateTimeConverter;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * @author Zhang
 * @date 2024-05-05
 */
public class TimeConverter {
    @Test
    public void testTimeConverter() {
//        long timestamp = 1631762560; // 示例时间戳，假设为 2021-04-21 08:00:00
        long timestamp = 1714895528064L; // 示例时间戳，假设为 2021-04-21 08:00:00
        LocalDateTime localDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(timestamp), java.time.ZoneId.of("Asia/Shanghai"));

        // 定义日期时间的格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 格式化 LocalDateTime 对象为字符串
        String formattedDateTime = localDateTime.format(formatter);
        System.out.println(formattedDateTime);
    }
}
